package com.cookor.poi.common.utils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class ResultUtil implements Serializable {

    public static String SUCCESS_CODE = "0";

    public static String ERROR_CODE = "-1";

    /* 状态码 */
    private String code;
    /* 提示信息 */
    private String message;
    /* 服务器异常信息 */
    private String error;
    /* 成功返回的数据 */
    private Map<String, Object> data;

    public ResultUtil(String code) {
        this.code = code;
    }

    public ResultUtil(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    // 如果已经存在错误码，就不设置
    public void setErrorCode(String code) {
        if (this.code.equals(ResultUtil.SUCCESS_CODE)){
            this.code = code;
        }
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public ResultUtil putParams(String key, Object value){
        if(this.data == null){
            data = new HashMap<String, Object>();
        }
        data.put(key, value);
        return this;
    }

    public static ResultUtil ErrorMsg(String msg){
        ResultUtil resultUtil = new ResultUtil(ResultUtil.ERROR_CODE);
        resultUtil.setError(msg);
        return resultUtil;
    }

}


